#ifndef _THREAD_POOL_H_
#define _THREAD_POOL_H_

#include <stdio.h>
#include <stdbool.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <semaphore.h>

#include <errno.h>
#include <pthread.h>

#define MAX_WAITING_TASKS	2000
#define MAX_ACTIVE_THREADS	30

#define BUFSIZE			100
#define PATHSIZE		500

#define THREDHOLD1 100
#define THREDHOLD2 300
#define THREDHOLD3 500

// 任务节点   <<<=====   p
struct task
{
	void *(*do_task)(void *arg);
	void *arg;

	struct task *next;
};

typedef struct thread_pool
{
	pthread_mutex_t lock; // 标准初始化流程
	pthread_cond_t  cond; // 标准初始化流程
	sem_t sem;

	bool shutdown; // 销毁线程池的标记

	struct task *task_list; // 任务链表

	pthread_t *tids; // 线程的id

	unsigned max_waiting_tasks;
	unsigned waiting_tasks;
	unsigned active_threads;
}thread_pool;


bool init_pool(thread_pool *pool, unsigned int threads_number);
bool add_task(thread_pool *pool, void *(*do_task)(void *arg), void *task);
int  add_thread(thread_pool *pool, unsigned int additional_threads_number);
int  remove_thread(thread_pool *pool, unsigned int removing_threads_number);
bool destroy_pool(thread_pool *pool);

void *routine(void *arg);


#endif
